<template>
  <div class="search">
    <div class="content">
      <div class="searchbox" @click="router.push('/searchpage')">
        <input type="text" placeholder='新增"专业搜索",筛作品超快！' />
        <span class="iconfont icon-sousuo_o"></span>
      </div>
      <div class="banner">
        <van-swipe>
          <van-swipe-item v-for="banner in banners" :key="banner.id"
            ><van-image
              radius="10rem"
              width="100%"
              height="200rem"
              :src="banner.cover"
            />
          </van-swipe-item>

          <template #indicator="{ active, total }">
            <div class="custom-indicator">{{ active + 1 }}/{{ total }}</div>
          </template>
        </van-swipe>
      </div>

      <div class="menu">
        <div v-for="(recommend, index) in recommended_position" :key="index">
          <div class="img">
            <img :src="recommend.icon" alt="" />
          </div>
          <p>{{ recommend.title }}</p>
        </div>
      </div>

      <div class="title">
        <h3>作品</h3>
        <p>全部作品</p>
      </div>

      <div class="list">
        <div
          class="item"
          v-for="item in categories"
          :key="item.id"
          @click="toWorks((item.id),(item.category_name))"
        >
          <span class="category">{{ item.category_name }}</span>
          <van-image
            width="157rem"
            height="120rem"
            lazy-load
            :src="item.cover"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { getDiscovery } from "../api/index";
const router = useRouter();
const banners = ref([]);
const recommended_position = ref([]);
const categories = ref([]);
getDiscovery().then((res) => {
  // console.log(res.data.data);
  banners.value = res.data.data.banners;
  // console.log(banners.value);
  recommended_position.value = res.data.data.recommended_position;
  categories.value = res.data.data.categories;
});

function toWorks(id,type) {
  router.push({
    path: "/works",
    query: {
      id,
      type:type
    },
  });
}
</script>

<style lang="scss" scoped>
.search {
  .content {
    padding-bottom: 50rem;
    .searchbox {
      padding: 15rem 20rem;
      position: relative;
      input {
        width: 100%;
        height: 30rem;
        line-height: 30rem;
        padding-left: 50rem;
        font-size: 14rem;
        border: none;
        background-color: #f0f0f0;
        border-radius: 5rem;
      }
      input::-webkit-input-placeholder {
        /*WebKit browsers*/
        color: #bdbdbd;
      }
      input::-moz-input-placeholder {
        /*Mozilla Firefox*/
        color: #bdbdbd;
      }
      span {
        font-size: 25rem;
        color: #bdbdbd;
        position: absolute;
        top: 17rem;
        left: 35rem;
      }
    }
    .banner {
      padding: 0rem 12rem;
      margin: 15rem 0rem 30rem;
      border-radius: 10rem;
      overflow: hidden;
    }
    .menu {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0rem 30rem;
      div {
        display: flex;
        flex-direction: column;
        align-items: center;
        .img {
          border-radius: 50%;
          background-color: #fff;
          box-shadow: 0px 0px 5px 1px grey;
        }
        img {
          width: 50rem;
          height: 50rem;
          transform: scale(0.6);
        }
        p {
          font-size: 12rem;
          color: #333;
          margin: 20rem;
        }
      }
    }
    .title {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      padding: 0rem 20rem;
      h3 {
        font-size: 18rem;
        color: #000;
        font-weight: bold;
      }
      P {
        font-size: 14rem;
        color: #d95751;
      }
    }
    .list {
      padding: 20rem;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .item {
        margin: 0rem 20rem 20rem 0rem;
        position: relative;
        top: 0;
        left: 0;
        &:nth-child(2n) {
          margin-right: 0rem;
        }
        img {
          width: 157rem;
          height: 120rem;
        }
        .category {
          font-size: 14rem;
          color: #fff;
          position: absolute;
          top: 12rem;
          left: 10rem;
          z-index: 10;
        }
      }
    }
  }
  .custom-indicator {
    position: absolute;
    right: 5px;
    bottom: 5px;
    padding: 2px 5px;
    font-size: 14rem;
    background: rgba(0, 0, 0, 0.1);
    color: white;
  }
  .van-swipe {
    border-radius: 10rem;
    overflow: hidden;
  }
  .goods-card {
    margin: 0;
    background-color: white;
  }
  .delete-button {
    height: 100%;
  }
}
</style>